

*	**********************************************************************
*	File Name: DyadAmnesties.do
*	Date:	April 27, 2017
*	Author: Geoff Dancy
*	Purpose: This file replicates the findings from "Deals with the 
*	Devil: Conflict Amnesties, Civil War, and Sustainable Peace" for the journal
*	International Organzation
*
*	Version: Stata 14 or above
*	**********************************************************************

*	**********************************************************************
*	Instructions for New Users:
*	Hi User, you will have to do a couple of things if you want this to work
*	on your computer. Step 1, save all of the input and do files listed below
*	to a folder on you computer. Step 2, rename the intial 
*	file directory on line 27 below.  Best, Geoff
*	**********************************************************************

*	Files you will need: DyadAmnesties.dta, fdbar1.csv, fdbar2.csv
*	**********************************************************************
	
	
	cd  "/Users/geoff/Dropbox/Amnesties_v3/FinalSubmission/ReplicationData/"
	*cd "Your file directory"
	
	
	
	***Summary Stats
	*********************************************
	
		** Pages 6-8
				
			use "DyadAmnesties.dta", clear

			*Counting amnesties
				tab dyam
				*297 total amnesties -- 289+(4x2)
				
			*Number of countries with amnesties
				use "DyadAmnesties.dta", clear
				collapse (sum) dyam, by(ccode)
				drop if ccode==.
				tab dyam
				*104-26 = 78 countries
				*78 - 30 one-time amnesty countries = 48 with more than one
			
	
		** Figure 1 and supporting stats
			
			use "DyadAmnesties.dta", clear
			sort conflictid year
			gen conflicts=1
			
			collapse (sum) dyam hram conflicts, by(year)
			gen amcon=dyam/conflicts
			gen sumam=dyam
			replace sumam=sum(dyam)
			gen sumhr=hram
			replace sumhr=sum(hram)
			drop if year>2010
			*77 HR Amnesties, 297 total (26%)
				
			display 297/(2010-1946)
			*4.64 amnesties per year
				
			twoway (line amcon year, lpattern(solid) ytitle(Percentage)) (line sumam year, yaxis(2) lpattern(dash)), ///
				xlabel(1945 (5) 2010,) legend(label(1 "% of Conflicts with Amnesties") label(2 "Cumulative Amnesties") col(3))
				*have to make some adjustments in graph editor
				
			drop if year<1975
			gen sum2am=dyam
			replace sum2am=sum(dyam)
				
			display 276/(2010-1975)
			*7.89 amnesties per year

			
		**Page 11 stats
			
			use "DyadAmnesties.dta", clear
			
			tab after
			*116 after
				
			tab during
			*181 during
				
			tab  hram
			*77 HR Amnesties
				
			tab pcagam after
			*57 in peace agreements after conflict
			
			
		**Page 25 stats
		
			use "DyadAmnesties.dta", clear
			drop if year>2010
			
			collapse (max) dyadterm recur victory, by(dyadep)
			*N=619
			
			tab dyadterm
			*588 terminations
			
			tab recur
			*182 recurrences
			
			display 182/588
			*31%
			
			drop if victory==1
			*163 victories
			
			tab dyadterm
			*425 terminations 
			
			tab recur
			*161 recurrences
			
			display 161/425
			*37.9%
			
			
		**Page 27 stats
		
			use "DyadAmnesties.dta", clear
			drop if year>2010
			
			tab doppam1 dyadterm
			*32 followed by termination
			
			display 32/181
			*17.7%
			
			tab dhram
			*29 during human rights amnesties
			
			tab dhram1 dyadterm
			*5 followed by termination
			
			display 5/29
			
		
		
	***Analysis Part 1 -- Dyad Termination
	*********************************************	
	
		use "DyadAmnesties.dta", clear
			drop if year>2010
		
		
		**Matching
		
			*Goes in Appendix Table 3
			
			imb transdum lsjicat territory intensitylevel dyamsum_l1, treatment(doppam1)
			
			cem transdum (#0) lsjicat (#0) territory (#0) intensitylevel (#0) dyamsum_l1 (0 1 1.5), treatment(doppam1) showbreaks
				drop if cem_matched==0
			
		
		**Model 1
			
			logit dyadterm doppam1 time [iw=cem_weights], cluster(conflictid) robust
				estimates store m1
				
				logit dyadterm i.doppam1 time [iw=cem_weights], cluster(conflictid) robust
				margins, dydx(doppam1) atmeans
				*13.8% less likely to terminate
		
		
		**Model 2
	
			logit dyadterm doppam1 dhram1 time [iw=cem_weights], cluster(conflictid) robust 
				estimates store m2
				
			*Figure 2
			
				set scheme s1mono
				
				logit dyadterm i.doppam1 i.dhram1 c.time [iw=cem_weights], cluster(conflictid) robust
				margins, dydx (doppam1) at(time=(1 5 10 15 20 25 30 35 40)) 
				marginsplot, yline(0) title(All Amnesties)
				graph save margallam.gph, replace
				*make changes with graph editor
				
				logit dyadterm i.doppam1 i.dhram1 c.time [iw=cem_weights], cluster(conflictid) robust
				margins, dydx (dhram1) at(time=(1 5 10 15 20 25 30 35 40))
				marginsplot, yline(0) title(Serious Violations Amnesties)
				graph save marghram.gph, replace
				*make some changes with graph editor
				
				graph combine margallam.gph marghram.gph

		
		**Model 3
		
			logit dyadterm doppam1 dhram1 postsl transdum lsji ///
				time ethnic territory intensitylevel numdyads ///
				dyamsum_l1 bop rebcap blood unpko ///
				poor logpop2 [iw=cem_weights], cluster(conflictid) robust

					estimates store m3
			
		**Model 4
	
			logit dyadterm dhram1 dnhram1 postsl transdum lsji ///
				time ethnic territory intensitylevel numdyads ///
				dyamsum_l1 bop rebcap blood unpko ///
				poor logpop2 [iw=cem_weights], cluster(conflictid) robust
				
					estimates store m4
			
		**Table 2		
				
			esttab m1 m2 m3 m4 using T2.tex, replace ///
				label ///
				cells(b(fmt(a3) star) se(par fmt(a3))) ///
				se scalars(N r2_p ll) ///
				star(* 0.10 ** 0.05 *** 0.01) ///
				title(Amnesties and Conflict Termination) /// 
				note(***p\sym{<}.01  **p\sym{<}.05  *p\sym{<}.10. Errors clustered by conflict)	///
				nonumbers mtitles("M1" "M2" "M3" "M4")	
		

		**Figure 3 
		
			*cd "Your file directory"
			use "DyadAmnesties.dta", clear
				drop if year>2010
			
			cem transdum (#0) lsjicat (#0) territory (#0) intensitylevel (#0) dyamsum_l1 (0 1 1.5), treatment(doppam1) showbreaks
				drop if cem_matched==0
			
			logit dyadterm i.doppam1 dhram1 postsl transdum lsji ///
				time ethnic territory intensitylevel numdyads ///
				dyamsum_l1 bop rebcap blood unpko ///
				poor logpop2 [iw=cem_weights], cluster(conflictid) robust
			
				margins, dydx(doppam1) atmeans	
				*12.6% less likely to recur
				
				*Manually input values into csv file, fdbar1.csv
		
		
			clear
			insheet using "fdbar1.csv" 
			
				set scheme s1mono
				#delimit;
				twoway (bar fd sec, barw(.4) color(gs6)) ||
				  (rcap fdlow fdhigh sec, lw(thin) color(black)) ||
				  (connected fd sec, lw(thin) color(black)),
				  xlabel(1.2 "Amnesty", labsize(medsmall))
				  ylabel(.1(-.1)-.3, val angle(horizontal))
				  ymtick(.1(-.1)-.3)
				  yline(0, lpattern(dash))
				  ytitle("Change in Expected Probability of Termination", size(medium) margin(medium))
				  xtitle(" ")
				  legend (off)
				  graphregion(color(white))
				  title("Model 3")
				   saving("fdbar1.gph", replace)
					;
					#delimit cr
			
			
			*cd "Your file directory"
			use "DyadAmnesties.dta", clear
				drop if year>2010
				
			cem transdum (#0) lsjicat (#0) territory (#0) intensitylevel (#0) dyamsum_l1 (0 1 1.5), treatment(doppam1) showbreaks
				drop if cem_matched==0
			
			
			logit dyadterm i.dnhram1 i.dhram1 postsl transdum lsji ///
				time ethnic territory intensitylevel numdyads ///
				dyamsum_l1 bop rebcap blood unpko ///
				poor logpop2 [iw=cem_weights], cluster(conflictid) robust
			
				margins, dydx(dnhram1) atmeans
				*change of -.124
				margins, dydx(dhram1) atmeans 
				*change of -.148
				
				*Manually input values into csv file, fdbar2.csv
			
				clear
				insheet using "fdbar2.csv"
					
					#delimit;
					twoway (bar fd sec, barw(.2) color(gs6)) ||
					  (rcap fdlow fdhigh sec, lw(thin) color(black)) ||
					  (connected fd sec, lw(thin) color(black)),
					  xlabel(1 "No Serious Violations" 1.4 "Serious Violations", labsize(medsmall))
					 ylabel(.1(-.1)-.3, val angle(horizontal))
					  ymtick(.1(-.1)-.3)
					  yline(0, lpattern(dash))
					   ytitle("Expected Probability of Termination", size(medium) margin(medium))
					  xtitle(" ")
					  legend (off)
					  graphregion(color(white))
					  title("Model 4")
					  text(-.15 1.2 "2.4%", place(s) color(black) size(large))
					   saving("fdbar2.gph", replace)
						;
						#delimit cr
			
			
				graph combine fdbar1.gph fdbar2.gph
			
		

	***Analysis Part 2 -- Dyad Recurrence
	*********************************************	
	
		use "DyadAmnesties.dta", clear
			drop if year>2010
		
		**St Set		
		
			stset dpcdur, fail(recur) id(dyadep)
			
			*Survival Curves (rescale and alter legend in graph editor)
		
				sts graph, by(thram tnhram)
				graph save hrsurv.gph, replace
				
				sts graph, by(pcagam npagam)
				graph save pcsurv.gph, replace
				
				graph combine hrsurv.gph pcsurv.gph
			
		
		**Summary stats (no longer used)
			
			*summarize dpcdur if (dyadterm==1 & toppam==0)
			*tab recur if (dyadterm==1 & dtoppam==0)
			
			*summarize dpcdur if (dyadterm==1 & toppam==1)
			*tab recur if (dyadterm==1 & toppam==1)
			
			*summarize dpcdur if (dyadterm==1 & thram==1)
			*tab recur if (dyadterm==1 & thram==1)
			*summarize dpcdur if (dyadterm==1 & tnhram==1)
			*tab recur if (dyadterm==1 & tnhram==1)
			
			*summarize dpcdur if pcagam==1
			*tab recur if pcagam==1 
			*summarize dpcdur if npagam==1
			*tab recur if npagam==1 
						
		
		**Matching	
			
			drop if dyadterm!=1	
			drop if victory==1
			
			replace dyadep = 59502 in 420
			*manually replacing an error in the UCDP data set
	
			
			*Goes in Table Appendix Table 5
			
			imb postsl territory numdyads bop, treatment(toppam)
			
			cem postsl (#0) territory (#0) numdyads2 (#0) weakreb (#0), treatment(toppam)
				drop if cem_matched==0
				*numdyads and weakreb are manually coarsened versions of numdyads and bop vars

		
		**Full Interaction (Run this first, generate missing variables in full model to trim from naive model)
		
			streg toppam thram pcagam postsl transdum lsji ///
				time ethnic territory intensitylevel numdyads ///
				dyamsum_l1 bop rebcap blood unpko poor logpop2, ///
				nohr distribution(weibull) share(cem_strata)
				
				predict e
				gen missing=1 if e==.
				
				estimates store m7	
		
		
		**Naive
		
			streg toppam if missing!=1, nohr distribution(weibull) share(cem_strata)
				estimates store m5
			
		
		**Naive Interactions
		
			streg toppam thram pcagam if missing!=1, nohr distribution(weibull) share(cem_strata) 
				estimates store m6
		
		
		**Split PAG
		
			streg pcagam npagam postsl transdum lsji ///
				time ethnic territory intensitylevel numdyads ///
				dyamsum_l1 bop rebcap blood unpko poor logpop2, ///
			    nohr distribution(weibull) share(cem_strata)
			
				estimates store m8
		
		**Split HR
		
			streg thram tnhram postsl transdum lsji ///
				time ethnic territory intensitylevel numdyads ///
				dyamsum_l1 bop rebcap blood unpko poor logpop2, ///
			    nohr distribution(weibull) share(cem_strata)
				
				estimates store m9
		
		
		**Coefplot
		
			coefplot (m8) (m9), ///
				order (pcagam npagam thram tnhram dyamsum_l1) ///
				drop(postsl transdum lsji ///
				time ethnic territory intensitylevel numdyads ///
			    bop rebcap blood unpko poor logpop2 _cons) xline(0) ///
				title("Less Likely <------- Recurrence -------> More Likely   ", size(med) margin(small))	
				*adjust variable labels in graph editor
		
		**Table 4
			
			esttab m5 m6 m7 m8 m9 using T4.tex, replace ///
				label ///
				cells(b(fmt(a3) star) se(par fmt(a3))) ///
				se scalars(N risk N_fail ll) ///
				star(* 0.10 ** 0.05 *** 0.01) ///
				title(Amnesties and Conflict Recurrence) /// 
				note(***p\sym{<}.01  **p\sym{<}.05  *p\sym{<}.10. Errors clustered by conflict)	///
				nonumbers mtitles("M5" "M6" "M7" "M8" "M9")

		
		
		
		
	***Appendix
	*****************************************
	
		use "DyadAmnesties.dta", clear
			drop if year>2010
			
		
		**Summary Table for Appendix (Table 5)

			estpost summarize dyadterm negot doppam1 dhram1 dnhram1 toppam thram tnhram pcagam npagam ///
			transdum postsl lsji ///
			time territory intensitylevel numdyads ///
			dyamsum_l1 bop rebcap blood unpko ///
			poor logpop2 demo unpko
			
			esttab using Table5.tex, replace label cells("count mean(fmt(2)) sd(fmt(2)) min(fmt(2)) max(fmt(2))")
			
			
		** Termination Pre-Analysis
		
			*Predicting amnesties
			logit doppam1 postsl transdum lsji ///
				time ethnic territory intensitylevel numdyads ///
				dyamsum_l1 bop rebcap blood unpko, robust
				
				estimates store pa1
			
				*How much variation is explained by matching vars? 
						
					logit doppam1 postsl transdum lsji ///
						time ethnic territory intensitylevel numdyads ///
						dyamsum_l1 bop rebcap blood unpko, robust
						
						lroc
						graph save roc1.gph, replace
						
					logit doppam1 postsl ///
						time ethnic numdyads ///
						bop rebcap blood unpko, robust
							 
						lroc
						graph save roc2.gph
						
					graph combine roc1.gph roc2.gph		
			
			
			*Predicting termination
			logit dyadterm postsl transdum lsji ///
				time ethnic territory intensitylevel numdyads ///
				dyamsum_l1 bop rebcap blood unpko, robust
				
				estimates store pa2
			
			*Full Model
			logit dyadterm doppam1 postsl transdum lsji ///
				time ethnic territory intensitylevel numdyads ///
				dyamsum_l1 bop rebcap blood unpko, robust
				
				estimates store pa3
			
			*Table 6
			esttab pa1 pa2 pa3 using T6.tex, replace ///
				label ///
				cells(b(fmt(a3) star) se(par fmt(a3))) ///
				se scalars(N r2_p ll) ///
				star(* 0.10 ** 0.05 *** 0.01) ///
				title(Amnesties and Conflict Termination) /// 
				note(***p\sym{<}.01  **p\sym{<}.05  *p\sym{<}.10. Robust standard errors reported.)	///
				nonumbers mtitles("Amnesties" "Termination" "Full Model")	
				
		
		** Recurrence Pre-Analysis
		
			drop if year>2010
			drop if dyadterm!=1	
			drop if victory==1
			stset dpcdur, fail(recur) id(dyadep)

		
			logit toppam postsl transdum lsji ///
				time ethnic territory intensitylevel numdyads ///
				dyamsum_l1 bop rebcap blood unpko, robust
			
				estimates store pa4
				
				
					*How much variation explained by matching vars?
				
					logit toppam postsl transdum lsji ///
						time ethnic territory intensitylevel numdyads ///
						dyamsum_l1 bop rebcap blood unpko, robust
			
						lroc
						graph save roc3.gph, replace
						
					logit toppam transdum lsji ///
						time ethnic intensitylevel ///
						dyamsum_l1 blood unpko, robust	
						
						lroc
						graph save roc4.gph, replace
						
						graph combine roc3.gph roc4.gph
			
			
			streg postsl transdum lsji ///
				time ethnic territory intensitylevel numdyads ///
				dyamsum_l1 bop rebcap blood unpko, nohr distribution(weibull) robust
			
				estimates store pa5
			
			streg toppam postsl transdum lsji ///
				time ethnic territory intensitylevel numdyads ///
				dyamsum_l1 bop rebcap blood unpko, nohr distribution(weibull) robust
			
				estimates store pa6
			
			*Table 7
			esttab pa4 pa5 pa6 using T7.tex, replace ///
				label ///
				cells(b(fmt(a3) star) se(par fmt(a3))) ///
				se scalars(N r2_p ll) ///
				star(* 0.10 ** 0.05 *** 0.01) ///
				title(Amnesties and Conflict Recurrence) /// 
				note(***p\sym{<}.01  **p\sym{<}.05  *p\sym{<}.10. Robust standard errors clustered by country.)	///
				nonumbers mtitles("Amnesties" "Recurrence" "Full Model")	
		
		
		
		**Recurrence without matching 
			
			use "DyadAmnesties.dta", clear
			drop if year>2010
			
			
				*St Set		
				drop if victory==1
				drop if dyadterm==0
				stset dpcdur, fail(recur) id(dyadep)
			
					
			
				*Full Interaction (Run this first, generate missing)
			
				streg toppam thram pcagam postsl transdum lsji ///
					time ethnic territory intensitylevel numdyads ///
					dyamsum_l1 bop rebcap blood unpko poor logpop2, ///
					nohr distribution(weibull) cluster(ccode)
					
					predict e
					gen missing=1 if e==.
					
					estimates store r7	
		
		
				*Naive
				
					streg toppam if missing!=1, nohr distribution(weibull) cluster(ccode)
						estimates store r5
					
				
				*Naive Interactions
				
					streg toppam thram pcagam if missing!=1, nohr distribution(weibull) cluster(ccode)
						estimates store r6
				
				
				*Split PAG
				
					streg pcagam npagam postsl transdum lsji ///
						time ethnic territory intensitylevel numdyads ///
						dyamsum_l1 bop rebcap blood unpko poor logpop2 if missing!=1, ///
						nohr distribution(weibull) cluster(ccode)
					
						estimates store r8
				
				*Split HR
				
					streg thram tnhram postsl transdum lsji ///
						time ethnic territory intensitylevel numdyads ///
						dyamsum_l1 bop rebcap blood unpko poor logpop2 if missing!=1, ///
						nohr distribution(weibull) cluster(ccode)
						
						estimates store r9
						
						esttab r5 r6 r7 r8 r9 using T8.tex, replace ///
						label ///
						cells(b(fmt(a3) star) se(par fmt(a3))) ///
						se scalars(N risk N_fail ll) ///
						star(* 0.10 ** 0.05 *** 0.01) ///
						title(Amnesties and Conflict Recurrence) /// 
						note(***p\sym{<}.01  **p\sym{<}.05  *p\sym{<}.10. Errors clustered by conflict)	///
						nonumbers mtitles("M5b" "M6b" "M7b" "M8b" "M9b")
				
		
			
